package main

import (
	"fmt"
	"io/ioutil"
	"regexp"
	"sort"
)

func main() {
	dat, err := ioutil.ReadFile("Archives/p022_names.txt")
	if err != nil {
		panic(err)
	}
	r, _ := regexp.Compile(`"([A-Z]+)"`)
	matchs := r.FindAllStringSubmatch(string(dat), -1)
	names := make([]string, len(matchs))
	for i := 0; i < len(matchs); i++ {
		names[i] = matchs[i][1]
	}
	sort.Strings(names)
	sum := 0
	for i := 0; i < len(names); i++ {
		a, n, name := 'A', 0, []byte(names[i])
		for j := 0; j < len(name); j++ {
			n += int(name[j]-byte(a)) + 1
		}
		sum += n * (i + 1)
	}
	fmt.Println(sum)
}
